package com.yanqu.road.server.cmd.union.cross;

import com.yanqu.road.entity.enums.eUnionSyncType;
import com.yanqu.road.entity.player.CrossUserBaseInfo;
import com.yanqu.road.entity.union.UnionMember;
import com.yanqu.road.pb.union.UnionProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.union.CrossUnionMgr;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.string.StringUtils;

@Cmd(code = Protocol.C_UNION_SET_NOTICE_READ_STATE, desc = "设置公告阅读状态")
public class CrossSetNoticeReadStateCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {

        UnionProto.UnionSetNoticeReadStateReqMsg reqMsg = UnionProto.UnionSetNoticeReadStateReqMsg.parseFrom(packet.getBytes());
        int state = reqMsg.getState();
        String unionUid = "";
        CrossUserBaseInfo userBaseInfo = CrossUserMgr.getCrossUserBaseInfo(packet.getPlayerId());
        if(userBaseInfo == null){
            ret = GameErrorCode.E_USER_NO_FOUND;
        }else {

            UnionMember member = CrossUnionMgr.getUnionMember(userBaseInfo.getUserBaseInfo().getUnionUid(), packet.getPlayerId());
            if(null == member || StringUtils.isNullOrEmpty(member.getUnionUid())){
                ret = GameErrorCode.E_UNION_NO_JOIN_UNION;
            }else {
                member.setNoticeReadState(state);
                unionUid = member.getUnionUid();
            }
        }
        MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.U_UNION_DETAIL, CrossUnionMgr.getUnionDetailMsg(unionUid, eUnionSyncType.Normal.getValue())));
    }

    @Override
    public void sendData() {

    }
}
